/**
 * 区域管理类型定义
 * @author Wu.Liang
 * @date 2025-01-21
 */

// 区域类型枚举
export enum RegionType {
  PROVINCE = 1,    // 省
  CITY = 2,        // 市
  DISTRICT = 3,    // 区县
  STREET = 4,      // 街道
  COMMUNITY = 5    // 社区
}

// 区域状态枚举
export enum RegionStatus {
  DISABLED = 0,    // 禁用
  ENABLED = 1      // 启用
}

// 社区状态枚举
export enum CommunityStatus {
  DISABLED = 0,    // 禁用
  ENABLED = 1      // 启用
}

// 楼栋状态枚举
export enum BuildingStatus {
  DISABLED = 0,    // 禁用
  ENABLED = 1      // 启用
}

// 房户状态枚举
export enum HouseholdStatus {
  VACANT = 0,      // 空置
  OCCUPIED = 1,    // 已入住
  DECORATING = 2,  // 装修中
  RENTED = 3       // 出租
}

// 房间类型枚举
export enum RoomType {
  ONE_ROOM = 1,    // 一室
  TWO_ROOM = 2,    // 两室
  THREE_ROOM = 3,  // 三室
  FOUR_PLUS = 4    // 四室及以上
}

// 产权类型枚举
export enum PropertyType {
  OWNED = 1,       // 自有
  RENTED = 2,      // 租赁
  OTHER = 3        // 其他
}

// 装修状态枚举
export enum DecorationStatus {
  ROUGH = 1,       // 毛坯
  SIMPLE = 2,      // 简装
  FINE = 3,        // 精装
  LUXURY = 4       // 豪装
}

// 居民类型枚举
export enum ResidentType {
  OWNER = 1,       // 业主
  TENANT = 2,      // 租户
  FAMILY = 3,      // 家属
  VISITOR = 4      // 访客
}

// 分页结果接口
export interface PageResult<T> {
  records: T[]
  total: number
  size: number
  current: number
  pages: number
}

// 树形节点接口
export interface TreeNode<T = unknown> {
  id: number | string
  label: string
  children?: TreeNode<T>[]
  [key: string]: unknown
}

// 统计数据类型
export interface StatisticsData {
  totalRegions: number
  totalCommunities: number
  totalBuildings: number
  totalHouseholds: number
  occupancyRate: number
  regionDistribution: Array<{
    name: string
    value: number
  }>
  communityDistribution: Array<{
    name: string
    value: number
  }>
}

// 表单验证规则
export const regionFormRules = {
  regionName: [
    { required: true, message: '请输入区域名称', trigger: 'blur' },
    { min: 2, max: 50, message: '区域名称长度在 2 到 50 个字符', trigger: 'blur' }
  ],
  regionCode: [
    { required: true, message: '请输入区域编码', trigger: 'blur' },
    { pattern: /^[A-Z0-9]{2,20}$/, message: '区域编码只能包含大写字母和数字，长度2-20位', trigger: 'blur' }
  ],
  regionType: [
    { required: true, message: '请选择区域类型', trigger: 'change' }
  ]
}

export const communityFormRules = {
  communityName: [
    { required: true, message: '请输入社区名称', trigger: 'blur' },
    { min: 2, max: 50, message: '社区名称长度在 2 到 50 个字符', trigger: 'blur' }
  ],
  regionId: [
    { required: true, message: '请选择所属区域', trigger: 'change' }
  ],
  address: [
    { required: true, message: '请输入社区地址', trigger: 'blur' }
  ],
  contactPhone: [
    { max: 20, message: '联系电话长度不能超过20个字符', trigger: 'blur' },
    { pattern: /^1[3-9]\d{9}$|^0\d{2,3}-?\d{7,8}$/, message: '请输入正确的联系电话格式', trigger: 'blur' }
  ],
  managerName: [
    { max: 50, message: '负责人姓名长度不能超过50个字符', trigger: 'blur' }
  ]
}

export const buildingFormRules = {
  buildingName: [
    { required: true, message: '请输入楼栋名称', trigger: 'blur' },
    { min: 2, max: 50, message: '楼栋名称长度在 2 到 50 个字符', trigger: 'blur' }
  ],
  buildingType: [
    { required: true, message: '请选择建筑类型', trigger: 'change' }
  ],
  communityId: [
    { required: true, message: '请选择所属社区', trigger: 'change' }
  ],
  status: [
    { required: true, message: '请选择状态', trigger: 'change' }
  ],
  floorCount: [
    { required: true, message: '请输入楼层数', trigger: 'blur' },
    { type: 'number' as const, min: 1, max: 100, message: '楼层数必须在1-100之间', trigger: 'blur' }
  ],
  unitCount: [
    { required: true, message: '请输入单元数', trigger: 'blur' },
    { type: 'number' as const, min: 1, max: 50, message: '单元数必须在1-50之间', trigger: 'blur' }
  ],
  unitsPerFloor: [
    { required: true, message: '请输入每层户数', trigger: 'blur' },
    { type: 'number' as const, min: 1, max: 20, message: '每层户数必须在1-20之间', trigger: 'blur' }
  ],
  structureType: [
    { required: true, message: '请选择结构类型', trigger: 'change' }
  ],
  undergroundFloor: [
    { type: 'number' as const, min: 0, max: 10, message: '地下层数必须在0-10之间', trigger: 'blur' }
  ],
  buildYear: [
    { pattern: /^\d{4}$/, message: '建设年份格式不正确', trigger: 'blur' }
  ],
  area: [
    { type: 'number' as const, min: 0, message: '建筑面积不能为负数', trigger: 'blur' }
  ],
  landArea: [
    { type: 'number' as const, min: 0, message: '占地面积不能为负数', trigger: 'blur' }
  ],
  buildingHeight: [
    { type: 'number' as const, min: 0, message: '建筑高度不能为负数', trigger: 'blur' }
  ],
  hasElevator: [
    { required: true, message: '请选择是否有电梯', trigger: 'change' }
  ],
  elevatorCount: [
    { type: 'number' as const, min: 0, max: 20, message: '电梯数量必须在0-20之间', trigger: 'blur' }
  ],
  address: [
    { max: 255, message: '详细地址长度不能超过255个字符', trigger: 'blur' }
  ]
}

export const householdFormRules = {
  householdCode: [
    { required: true, message: '请输入房户编码', trigger: 'blur' },
    { max: 50, message: '房户编码长度不能超过50个字符', trigger: 'blur' }
  ],
  unitId: [
    { required: true, message: '请选择所属单元', trigger: 'change' }
  ],
  floorNumber: [
    { required: true, message: '请输入楼层号', trigger: 'blur' },
    { type: 'number', min: 1, max: 100, message: '楼层号必须在1-100之间', trigger: 'blur' }
  ],
  roomNumber: [
    { required: true, message: '请输入房间号', trigger: 'blur' },
    { max: 20, message: '房间号长度不能超过20个字符', trigger: 'blur' }
  ],
  roomType: [
    { required: true, message: '请选择房间类型', trigger: 'change' }
  ],
  area: [
    { type: 'number', min: 0, max: 1000, message: '房屋面积必须在0-1000平方米之间', trigger: 'blur' }
  ]
} 